package com.taotao.designpattern.state.multi;

import com.taotao.designpattern.state.Event;
import com.taotao.designpattern.state.State;

import java.util.Arrays;
import java.util.List;

/**
 * 复杂调度逻辑
 */
public class NewStateMachine extends AbstructStateMachine {
    @Override
    List<SopProcess> init() {
        return Arrays.asList(
                SopProcess.builder()
                        .from(State.HR_CHECK)
                        .event(Event.PASS)
                        .to(State.LEADER_CHECK)
                        .build(),

                SopProcess.builder()
                        .from(State.LEADER_CHECK)
                        .event(Event.PASS)
                        .to(State.FINISH)
                        .stateHandle(new LeaderPassHandle())
                        .build());
    }

    public static void main(String[] args) {
        NewStateMachine newStateMachine = new NewStateMachine();
        State state = newStateMachine.getNext(State.LEADER_CHECK, Event.PASS);
        System.out.println(state);
        // 执行状态转化处理逻辑
        IStateHandle<String, String> stateHandle = newStateMachine.getHandle(State.LEADER_CHECK, Event.PASS);
        if(null == stateHandle){
            System.out.println("没有设置stateHandle");
        }
        String result = stateHandle.handle("123");
        System.out.println(result);
    }
}